package com.tanhua.server.service;

import com.tanhua.dubbo.api.UserLocationApi;
import com.tanhua.model.mongodto.UserLocationDto;
import com.tanhua.model.vo.ErrorResult;
import com.tanhua.server.exception.BusinessException;
import com.tanhua.server.interceptor.UserHolder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class BaiduService {

    @DubboReference
    private UserLocationApi userLocationApi;

    /**
     *上报地理位置
     * @param dto
     */
    public void location(UserLocationDto dto) {
        Long userId = UserHolder.getUserId();
        //调用API存储地理数据
        Boolean update = userLocationApi.saveOrUpdate(dto, userId);
        if (!update){
            throw new BusinessException(ErrorResult.error());
        }
    }
}
